package com.cx.service.czw.impl;

import com.cx.mapper.PageMapper;
import com.cx.mapper.ReceiveAddressMapper;
import com.cx.mapper.SendAddressMapper;
import com.cx.pojo.Page;
import com.cx.pojo.PageExample;
import com.cx.pojo.wjr.UserPage;
import com.cx.service.czw.UserPageInfoService;
import com.cx.vo.UserDetailPageInfo;
import com.cx.vo.UserReceivePageInfo;
import com.cx.vo.UserSendPageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserPageInfoImpl implements UserPageInfoService {

    @Autowired
    SendAddressMapper sendAddressMapper;
    @Autowired
    ReceiveAddressMapper receiveAddressMapper;
    @Autowired
    PageMapper pageMapper;

    //查询全部收的快递
    @Override
    public List<UserReceivePageInfo> selectReceivePageInfo(String phone) {
        List<UserReceivePageInfo> userReceivePageInfoList = receiveAddressMapper.selectReceivePageInfo(phone);
        if(0 != userReceivePageInfoList.size()){
            return userReceivePageInfoList;
        }
        return null;
    }

    //查询全部寄过的快递
    @Override
    public List<UserSendPageInfo> selectSendPageInfo(String phone) {
        List<UserSendPageInfo> userSendPageInfoList = sendAddressMapper.selectSendPageInfo(phone);
        System.out.println(userSendPageInfoList);
        if(0 != userSendPageInfoList.size()){
            return userSendPageInfoList;
        }
        return null;
    }
    //通过快递编码查询收到的快递
    @Override
    public List<UserReceivePageInfo> selectReceivePageInfoByPageNum(String phone, String pageNum) {
        List<UserReceivePageInfo> userReceivePageInfoList = receiveAddressMapper.selectReceivePageInfoByPageNum(phone , Integer.parseInt(pageNum));
        if(0 != userReceivePageInfoList.size()){
            return userReceivePageInfoList;
        }
        return null;
    }
    //通过快递编码查询寄过的快递
    @Override
    public List<UserSendPageInfo> selectSendPageInfoByPageNum(String phone, String pageNum) {
        List<UserSendPageInfo> userSendPageInfoList = sendAddressMapper.selectSendPageInfoByPageNum(phone , Integer.parseInt(pageNum));
        if(0 != userSendPageInfoList.size()){
            return userSendPageInfoList;
        }
        return null;
    }
    //通过寄件人电话查询收到的快递
    @Override
    public List<UserReceivePageInfo> selectReceivePageInfoBySendPhone(String phone, String sendPhone) {
        List<UserReceivePageInfo> userReceivePageInfoList = receiveAddressMapper.selectReceivePageInfoBySendPhone(phone ,sendPhone);
        if(0 != userReceivePageInfoList.size()){
            return  userReceivePageInfoList;
        }
        return null;
    }
    //通过收件人电话查询寄过的快递
    @Override
    public List<UserSendPageInfo> selectSendPageInfoByReceivePhone(String phone, String receivePhone) {
        List<UserSendPageInfo> userSendPageInfoList = sendAddressMapper.selectSendPageInfoByReceivePhone(phone ,receivePhone);
        if(0 != userSendPageInfoList.size()){
            return  userSendPageInfoList;
        }
        return null;
    }
    //点击查询快递详细信息
    @Override
    public UserDetailPageInfo selectUserDetailPageInfo(Integer pageNum) {
        System.out.println(pageNum);
        UserDetailPageInfo userDetailPageInfo = pageMapper.selectDetailPageInfo(pageNum);
        System.out.println("详细快递信息 = " + userDetailPageInfo);
        if(null != userDetailPageInfo){
            return userDetailPageInfo;
        }
        return null;
    }

    //查询所有快递信息
    @Override
    public List<UserDetailPageInfo> selectAllPageInfo() {
        List<UserDetailPageInfo> userDetailPageInfoList = pageMapper.selectAllPageInfo();
        if(null != userDetailPageInfoList){
            return userDetailPageInfoList;
        }
        return null;
    }

    //已取消快递 的删除 delete
    @Override
    public int deleteCancelPage(Integer pageNum) {
        PageExample pageExample =new PageExample();
        pageExample.createCriteria().andPageNumEqualTo(pageNum);
        Page page = new Page();
        page.setStatus("已删除");
        int affectedRows = pageMapper.updateByExampleSelective(page ,pageExample);
        if(0 != affectedRows){
            return  affectedRows;
        }
        return 0;
    }
    //已下单快递 的取消 update
    @Override
    public int cancelOrderPage(Integer pageNum) {
        PageExample pageExample =new PageExample();
        pageExample.createCriteria().andPageNumEqualTo(pageNum);
        Page page = new Page();
        page.setStatus("已取消");
        int affectedRows = pageMapper.updateByExampleSelective(page ,pageExample);
        if(0 != affectedRows){
            return  affectedRows;
        }
        return 0;
    }
     //查 通过pageNum
    @Override
    public List<UserDetailPageInfo> selectPageByPageNum(Integer pageNum) {
        List<UserDetailPageInfo> userDetailPageInfoList = pageMapper.selectPageByPageNum(pageNum);
        if(null != userDetailPageInfoList || userDetailPageInfoList.size()>0){
            return userDetailPageInfoList;
        }
        return null;
    }
    //查 通过 receivePhone
    @Override
    public List<UserDetailPageInfo> selectPageByReceivePhone(String receivePhone) {
        List<UserDetailPageInfo> userDetailPageInfoList = pageMapper.selectPageByReceivePhone(receivePhone);
        if(null != userDetailPageInfoList || userDetailPageInfoList.size()>0){
            return userDetailPageInfoList;
        }
        return null;
    }
    //查 通过 receiveName
    @Override
    public List<UserDetailPageInfo> selectPageByReceiveName(String receiveName) {
        List<UserDetailPageInfo> userDetailPageInfoList = pageMapper.selectPageByReceiveName(receiveName);
        if(null != userDetailPageInfoList || userDetailPageInfoList.size()>0){
            return userDetailPageInfoList;
        }
        return null;
    }
}
